//
//  TicketBusinessRootController.m
//  ELife
//
//  Created by xiaozhi on 11-7-23.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "TicketBusinessRootController.h"
#import "UIViewUtil.h"
#import "TicketBusinessListController.h"

@implementation TicketBusinessRootController
@synthesize cityLabel;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

- (void)dealloc
{
    [cityLabel release];
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    [self setTitle:@"票务"];
    self.view.backgroundColor = [UIViewUtil getCommonBg];
    [UIViewUtil viewRoundFrame:[self.view viewWithTag:1]];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)openCityList
{
    UIActionSheet *cityActionSheet = [[UIActionSheet alloc] initWithTitle:@"城市列表" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:
                                      @"北京",
                                      @"上海",
                                      @"重庆",
                                      @"成都",
                                      @"广州",
                                      @"南京",
                                      nil];
    [cityActionSheet showInView:self.view];
    [cityActionSheet release];
}

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    const NSArray *_cityCodes = [NSArray arrayWithObjects:@"010", @"021", @"023", @"028",@"020", @"025", nil];
    _cityCode = [_cityCodes objectAtIndex:buttonIndex];
    
    [cityLabel setText:[actionSheet buttonTitleAtIndex:buttonIndex]];
    
    NSLog(@"CityCode:%@", _cityCode);
}

- (void)next
{
    if (_cityCode == nil) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"提醒" message:@"请您先选择城市" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alertView show];
        [alertView release];
        return;
    }
    
    TicketBusinessListController *nextController = [[TicketBusinessListController alloc]initWithNibName:@"TicketBusinessListController" bundle:nil];
    nextController.cityCode = _cityCode;
    [self.navigationController pushViewController:nextController animated:YES];
    [nextController release];
}

@end
